package com.work.game.home.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.work.game.R;
import com.work.game.home.ui.activity.GoodDetailActivity;
import com.work.game.home.ui.model.Good;
import com.work.game.utils.GlideImageLoader;

import java.util.List;

public class GoodsCateAdapter extends BaseAdapter implements View.OnClickListener {
    private final Context mContext;
    private final List<Good> goodList;

    public GoodsCateAdapter(Context context, List<Good> goodList) {
        this.mContext = context;
        this.goodList = goodList;
    }

    @Override
    public int getCount() {
        return goodList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_goods, null);

        }
        Good goods = goodList.get(position);
        new GlideImageLoader().displayImage(mContext, goods.getPgUrl(), convertView.findViewById(R.id.pic));
        TextView name = convertView.findViewById(R.id.name);
        name.setText(goods.getPgTitle());
        convertView.setOnClickListener(this);
        convertView.setTag(goods.getId());
        return convertView;
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(mContext, GoodDetailActivity.class);
        intent.putExtra("id", v.getTag().toString());
        mContext.startActivity(intent);
    }
}
